/*
 *    Copyright (c) 2018-2025, lengleng All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: lengleng (wangiegie@gmail.com)
 */
package com.pig4cloud.pigx.shop.user.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pig4cloud.pigx.common.core.util.R;
import com.pig4cloud.pigx.common.excel.vo.ErrorMessage;
import com.pig4cloud.pigx.shop.user.api.entity.ShopUserNickName;
import com.pig4cloud.pigx.shop.user.api.vo.ShopUserNickNameExcelVO;
import com.pig4cloud.pigx.shop.user.mapper.ShopUserNickNameMapper;
import com.pig4cloud.pigx.shop.user.service.ShopUserNickNameService;
import org.springframework.stereotype.Service;
import org.springframework.validation.BindingResult;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * 用户昵称库
 *
 * @author pigx code generator
 * @date 2023-12-13 19:30:48
 */
@Service
public class ShopUserNickNameServiceImpl extends ServiceImpl<ShopUserNickNameMapper, ShopUserNickName>
		implements ShopUserNickNameService {

	/**
	 * 导入用户昵称数据
	 * @param excelVOList
	 * @param bindingResult
	 * @return
	 */
	@Override
	public R importUserNickName(List<ShopUserNickNameExcelVO> excelVOList, BindingResult bindingResult) {
		List<ErrorMessage> errorMessageList = (List<ErrorMessage>) bindingResult.getTarget();
		excelVOList.forEach(item -> {
			ShopUserNickName record = new ShopUserNickName();
			// String nickName = item.getNickName().substring(3,
			// item.getNickName().length());
			String nickName = item.getNickName();
			record.setNickName(nickName);
			this.save(record);
		});

		// 数据不合法情况
		// Set<String> errorMsg = new HashSet<>();
		// errorMsg.add("不能为空");
		// errorMessageList.add(new ErrorMessage(10L, errorMsg));
		// if (CollUtil.isNotEmpty(errorMessageList)) {
		// return R.failed(errorMessageList);
		// }
		return R.ok();
	}

}
